fix(psbt): route addOutput unknownKeyVals to output map - #21
Draft
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
Draft
fix(psbt): route addOutput unknownKeyVals to output map#21bitgo-ai-agent-dev[bot] wants to merge 1 commit into
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
Conversation
addOutput() was calling addUnknownKeyValToInput(outputIndex, keyVal)
instead of addUnknownKeyValToOutput(outputIndex, keyVal). This caused
two confirmed failure modes:
1. Silent corruption when outputIndex < inputs.length: the keyval was
attached to inputs[outputIndex].unknownKeyVals and survived
serialize/parse round-trips in the wrong (input) map. Because the
duplicate-check also ran against InputTypes (16 entries) instead of
OutputTypes (6 entries), output unknown-key type bytes 6–15 were
additionally misrejected.
2. Crash ("No input #N") when outputIndex >= inputs.length — the
common 1-input/2-output case — making PSBT construction impossible
whenever unknownKeyVals accompany the second output.
Both modes affect musig2/MPC coordination data carried as output
proprietary fields: the signing ceremony crashes or corrupts the PSBT,
leaving funds stuck in the shared wallet.
Fix: change line 159 to call addUnknownKeyValToOutput, matching the
upstream bip174 v2.1.1 fix. Add regression tests covering correct
placement, round-trip survival, and the outputs>inputs case.
Ticket: WCN-1934
Session-Id: 9abd2e08-b701-4f8d-9355-06124e17bf0c
Task-Id: edef13cc-a93b-4c12-85ac-d51bcc1dfaaa
ralph-bitgo
Bot
force-pushed
the
fix/WCN-1934-addOutput-unknownKeyVals-routing-pt1
branch
from
August 7, 2026 20:02
7f1bff3 to
b9b3f18
Compare
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
`this.addUnknownKeyValToInput(outputIndex, keyVal)` →
`this.addUnknownKeyValToOutput(outputIndex, keyVal)`.
(not `inputs[N].unknownKeyVals`) and survive a `toHex()`/`fromHex()` round-trip.
of outputs exceeds the number of inputs (e.g. 1-input / 2-output transactions).
Why
`addOutput()` was calling the input variant of `addUnknownKeyVal` instead of
the output variant, causing two confirmed failure modes (WCN-1934 / FND-001):
Silent corruption when `outputIndex < inputs.length`: the keyval was
attached to `inputs[outputIndex].unknownKeyVals` and survived
serialize/parse round-trips in the wrong map. The PSBT proprietary-key
support added for musig2/MPC coordination data (commit 8a33996) was
completely broken: co-signers never found the required output metadata,
causing signing ceremonies to fail with funds stuck.
Crash (`"No input #N"`) when `outputIndex >= inputs.length` — the
common 1-input / 2-output case — making PSBT construction impossible
whenever `unknownKeyVals` accompany outputs beyond the first.
Additionally, the old code ran the duplicate/type guard against `InputTypes`
(16 entries) instead of `OutputTypes` (6 entries), so output unknown keys with
type byte 6–15 were additionally misrejected. This is addressed in pt2.
Test plan
Stack
This PR is part 1 of 2 in a stack. Review and merge in order:
Ticket: WCN-1934